<template>
  <div class="mg16 flex_start">
    <apply-left :setpData="setpData"></apply-left>
    <div class="apply_right">
      <div class="apply_body">
        <steps-demo :stepsList="stepsList"></steps-demo>
        <div class="body">
          <div class="top" v-if="isShow && setpData.stepExaminetwoStatus != 3">
            <span class="mn_a">
              <i class="el-icon-warning"
                style="color: #0c7ff2; font-size: 14px; padding-right: 6px"></i>提示:请耐心等待审核结果，我们将会在3个工作日内进行审核。
            </span>
            <i class="el-icon-close" style="color: #85bff8; cursor: pointer" @click="isShow = false"></i>
          </div>
          <div class="top2" v-if="setpData.stepExaminetwoStatus == 3">
            <span class="mn_a">
              <i class="el-icon-warning"
                style="color: #ff6332; font-size: 14px; padding-right: 6px"></i>提示：您上传的赞助报告被驳回，驳回原因：{{ message }}
            </span>
          </div>
          <el-form ref="reportData" id="fileupload" method="POST" :rules="rules" enctype="multipart/form-data"
            :model="reportData" label-width="166px">
            <div id="first" class="target-fix" />
            <div class="essentialInformation">
              <p class="essentialInformation_text">基本信息</p>
              <div class="form">
                <el-form-item label="报告名称:" prop="title">
                  <el-input v-model="reportData.title" maxlength="40" show-word-limit placeholder="请输入报告名称" class="w456"
                    size="small" />
                </el-form-item>
                <el-form-item label="报告简介:" prop="content">
                  <el-input v-model="reportData.content" type="textarea" :autosize="{ minRows: 3, maxRows: 5 }"
                    maxlength="200" show-word-limit placeholder="请输入视频名称" class="w456" size="small" />
                </el-form-item>
              </div>
            </div>
            <div id="second" class="target-fix" />
            <div class="essentialInformation mt10">
              <p class="essentialInformation_text mt10">参会嘉宾</p>
              <div class="form flex">
                <el-form-item label="参会嘉宾:" prop="authorID">
                  <el-select v-model="reportData.authorID" filterable placeholder="请选择" @change="changeContent">
                    <el-option v-for="item in options" :key="item.id" :label="item.authorName" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
                <span class="mn_butn" @click="$refs.addAuthorDia.addAuthorDia = true">+ 新增嘉宾</span>
              </div>
            </div>
          </el-form>
        </div>
        <div class="btm_butn" v-if="setpData.stepExaminetwoStatus == 1">
          <el-button type="primary" @click="saveAddCompanuyReport('reportData')">提交审核</el-button>
        </div>
        <div class="btm_butn" v-if="setpData.stepExaminetwoStatus == 3">
          <el-button type="danger" @click="saveAddCompanuyReport('reportData')">重新提交审核</el-button>
        </div>
      </div>
    </div>
    <add-author ref="addAuthorDia" @renovate="renovate"></add-author>
  </div>
</template>
<script>
import applyLeft from "../compontents/left.vue";
import stepsDemo from "../compontents/Steps.vue";
import addAuthor from '@/views/selfCreate/components/addAuthor.vue'
import api from "@/api/index";
import { changeDateFormat } from "@/utils/commin";
export default {
  components: {
    applyLeft,
    stepsDemo,
    addAuthor
  },
  data() {
    return {
      stepsList: ["填写赞助报告的内容", "提交报告内容审核"],
      isShow: true,
      setpData: {
        step: 2,
        stepExamineOneStatus: 4,
        stepExaminetwoStatus: 1,
      },
      options: [],
      reportData: {
        title: "",
        content: "",
        authorID: "",
        authorImg: "",
        author: "",
      },
      message: "",
      rules: {
        title: [{ required: true, message: "请输入报告名称", trigger: "blur" }],
        content: [
          { required: true, message: "请输入报告简介", trigger: "blur" },
        ],
        authorID: [
          {
            required: true,
            message: "请选择参会嘉宾",
            trigger: "change",
          },
        ],
      },
    };
  },
  mounted() {
    if (this.$route.query.reportMid) {
      this.getSponsorState();
      this.getSponsorReport();
    }
    this.getAuthors();
  },
  methods: {
    renovate() {
      this.getAuthors();
    },
    changeContent(val) {
      const obj = this.options.filter(item => {
        if (val == item.id) {
          return item
        }
      })
      this.reportData.authorImg = obj.img
      this.reportData.author = obj.authorName
    },
    //提交
    saveAddCompanuyReport(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          api.support.saveAddCompanuyReport(this.reportData).then((res) => {
            this.$message({ type: "success", message: "提交成功" });
            this.$router.push('/support/index')
          });
        } else {
          return false;
        }
      });
    },
    async getAuthors() {
      let form = {
        imshowId: this.$store.getters.imShowId,
      };
      const { data } = await api.support.getAuthors(form);
      this.options = data;
      this.options.forEach((item) => {
        item.id = item.id + "";
      });
    },
    getSponsorReport() {
      let form = {
        imshowId: this.$store.getters.imShowId,
        mid: this.$route.query.reportMid,
      };
      api.support.getSponsorReport(form).then((res) => {
        this.reportData = res.data;
      });
    },
    async getSponsorState() {
      let form = {
        imshowId: this.$store.getters.imShowId,
        id: this.$route.query.id,
      };
      const { data } = await api.support.getSponsorState(form);
      if (data.state == 10) {
        if (this.$route.query.examine == 1) {
          this.setpData.stepExaminetwoStatus = 2;
        } else {
          this.setpData.stepExaminetwoStatus = 1;
        }
      } else if (data.state == 12) {
        this.setpData.stepExaminetwoStatus = 3;
      } else {
        this.setpData.stepExaminetwoStatus = 4;
      }
      this.message = data.message;
    },
  },
};
</script>
    
<style lang="scss" scoped>
.w456 {
  width: 456px !important;
}

.mn_butn {
  display: inline-block;
  padding: 6px 20px;
  border-radius: 4px 4px 4px 4px;
  border: 1px solid #85bff8;
  font-size: 14px;
  color: #0c7ff2;
  height: 19px;
  margin-left: 20px;
  margin-top: 4px;
  cursor: pointer;
}

.table_logo {
  width: 55px;
  height: 32px;
  display: inline-block;
  padding: 2px 4px;
  border: 1px solid #f0f3f7;
  margin-right: 8px;
  object-fit: contain;
}

.btm_butn {
  padding: 23px;
  border-top: 1px solid #e5eaf0;
  margin-top: 23px;
  text-align: center;
}

.flex_start {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}

.apply_right {
  margin-left: 16px;
  flex-grow: 1;
  width: 50%;

  .apply_body {
    background: #fff;

    .body {
      border-top: 1px solid #f0f3f7;
      padding: 20px;

      .top {
        padding: 8px 16px;
        background: #e7f2fe;
        border-radius: 4px 4px 4px 4px;
        @include flex(row, center, space-between);
        color: #4f5862;
        font-size: 12px;
      }

      .top2 {
        padding: 8px 16px;
        background: #ffefeb;
        border-radius: 4px 4px 4px 4px;
        @include flex(row, center, space-between);
        color: #4f5862;
        font-size: 12px;
      }

      .instrument-edit-ruleForm::v-deep .el-form-item__label {
        color: #202933;
      }

      .instrument-edit-ruleForm::v-deep .el-form-item {
        margin-bottom: 32px;
      }

      .instrument-edit-ruleForm::v-deep .el-form-item:last-child {
        margin-bottom: 0;
      }

      .instrument-edit-ruleForm::v-deep .formItemInner {
        margin-bottom: 0;
      }

      .instrument-edit-ruleForm::v-deep .el-form-item__content {
        line-height: 32px;
      }

      .instrumentListBox {
        // width: 1436px;
        box-shadow: inset 0px -1px 0px 1px #dde2e8;
        padding: 16px;
        background: #f5f8fc;
        margin: 0 auto;
      }

      .essentialInformation {
        // width: 1404px;
        padding-bottom: 15px;
        background: #ffffff;
        padding-top: 24px;
        padding-left: 16px;
        margin: 0 16px;
      }

      .essentialInformation_text {
        font-size: 16px;
        font-weight: bold;
        line-height: 30px;
        margin: 0;
        padding-left: 12px;
        border-left: 4px solid #0c7ff2;
        line-height: 16px;
        margin-bottom: 20px;
      }
    }
  }
}
</style>